home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: EventLoop.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
-
-
- /*****************************************************************************/
-
-
-
- extern RgnHandle gCursorRgn; /* DTS.Lib..framework global. */
- /* The current cursor region. The initial cursor region is an empty region,
- ** which will cause WaitNextEvent to generate a mouse-moved event, which will
- ** cause us to set the cursor for the first time. */
-
- extern Boolean gQuitApplication; /* DTS.Lib..framework global. */
- /* This is set to false by Initialize. When the user selects Quit
- ** (and does not abort the quit), then this boolean is set true. */
-
- Boolean gLowOnMem;
- static void ManageLowMem(void);
-
- #define kRamReserve 0x10000L
- #define kRamSlop 0x08000L
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Get events forever, and handle them by calling DoEvent. Get the events by
- ** calling WaitNextEvent. */
-
- #pragma segment Main
- void EventLoop(void)
- {
- EventRecord event;
-
- while (!gQuitApplication) {
- ManageLowMem();
- if (!WaitNextEvent(everyEvent, &event, 15, gCursorRgn))
- event.what = nullEvent;
- DoEvent(&event);
- };
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called to determine if there is enough ram available for various
- ** application operations. Typically, if there is not enough, certain menu
- ** items are dimmed, thus preventing further use of memory. */
-
- #pragma segment Main
- static void ManageLowMem(void)
- {
- static Handle reserveMemHndl;
-
- if (!reserveMemHndl) {
- reserveMemHndl = NewHandle(0);
- EmptyHandle(reserveMemHndl);
- }
-
- if (gLowOnMem) {
- ReallocateHandle(reserveMemHndl, kRamReserve + kRamSlop);
- if (*reserveMemHndl) {
- SetHandleSize(reserveMemHndl, kRamReserve);
- HPurge(reserveMemHndl);
- gLowOnMem = false;
- }
- }
- else {
- if (!*reserveMemHndl) {
- ReallocateHandle(reserveMemHndl, kRamReserve);
- if (*reserveMemHndl) HPurge(reserveMemHndl);
- else {
- NewDocumentWindow(nil, 'LMEM', false);
- gLowOnMem = true;
- }
- }
- }
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* •• Called by DTS.Lib..framework. •• */
-
- /* Handle the cursor changes. Most of the work is done by the application
- ** framework. Each window has its own cursor calculation proc, so you
- ** shouldn't have to add any code here. You may wish to do some special
- ** stuff prior to the DoWindowCursor call if you have modeless dialogs. */
-
- #pragma segment Main
- void DoCursor(void)
- {
- DoWindowCursor();
- }
-
-
-
-